package pers.xhh.shopapi.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pers.xhh.shopapi.annotation.UserLoginToken;
import pers.xhh.shopapi.common.Mi;
import pers.xhh.shopapi.service.MiPermissionService;

import javax.servlet.http.HttpServletRequest;

/**
 * @author wei-xhh
 * @date 2020-11-24
 */
@CrossOrigin
@RestController
@RequestMapping("/api/v1")
public class MiPermissionController {

    @Autowired
    MiPermissionService miPermissionService;

    @UserLoginToken
    @GetMapping("/rights/{type}")
    public Mi getPermissions(@PathVariable("type") String type){
        return miPermissionService.listPermission(type);
    }

    @UserLoginToken
    @GetMapping("/menus")
    public Mi getMenus(HttpServletRequest request){
        String authorization = request.getHeader("Authorization");
        return miPermissionService.getMenus(authorization);
    }
}
